/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AvoidanceReportWindow.java
 *
 * Created on Jun 14, 2010, 5:13:43 PM
 */
package com.lct.eq2.gui;

import com.lct.eq2.data.Attack;
import com.lct.eq2.data.AttackHashMap;
import com.lct.eq2.data.Combatant;
import com.lct.eq2.data.Encounter;
import com.lct.eq2.gui.LiteGui.PieRenderer;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Vector;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JList;
import javax.swing.table.DefaultTableModel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.util.Rotation;

/**
 *
 * @author A59287
 */
public class AvoidanceReportWindow extends javax.swing.JFrame {

    private Encounter enc;
    private JFreeChart chart;

    /** Creates new form AvoidanceReportWindow */
    public AvoidanceReportWindow(Encounter enc) {
        this.setIconImage(Toolkit.getDefaultToolkit().getImage("eq2.png"));
        this.enc = enc;
        initComponents();
//        this.populateTable();
        this.populateList(enc, true, true);
    }

    public void populateList(Encounter enc, boolean listAllies, boolean listEnemies) {
        DefaultListModel model = (DefaultListModel) this.jList1.getModel();
        model.clear();
        ArrayList<Combatant> combatants = enc.getCombatants();
        for (Combatant combatant : combatants) {
            if (combatant.getAvoidedAtLeastOne() == null || (combatant.getAvoidedAtLeastOne() != null && combatant.avoidedAtLeastOne())) {
                if (listAllies) {
                    if (enc.isAlly(combatant.getName())) {
                        model.add(model.getSize(), combatant);
                    } else if (listEnemies) {
                        model.add(model.getSize(), combatant);
                    }
                } else if (listEnemies) {
                    if (!enc.isAlly(combatant.getName())) {
                        model.add(model.getSize(), combatant);
                    } else if (listAllies) {
                        model.add(model.getSize(), combatant);
                    }
                }
            }
        }
        Combatant c = (Combatant) model.getElementAt(0);
        this.generateAvoidanceReport(c);
    }

    private int generateAvoidanceReport(Combatant c) {
        int rval = 0;

        lblSpellReflect.setText("Reflect:");
        lblResist.setText("Resist:");
        lblMeleeReflect.setText("Reflect:");
        lblCounter.setText("Counter:");
        lblDeflect.setText("Deflect:");
        lblRiposte.setText("Riposte:");
        lblMiss.setText("Miss:");
        lblDodge.setText("Dodge:");
        lblParry.setText("Parry:");
        lblMeleeBlock.setText("Block:");
        lblMeleeTotal.setText("Total:");
        lblNonMeleeTotal.setText("Total:");

        double totalAvoids = 0;
        if (c != null) {
            int counters = 0;
            int meleeReflects = 0;
            int deflects = 0;
            int ripostes = 0;
            int dodges = 0;
            int parries = 0;
            int meleeBlocks = 0;
            int nonMeleeBlocks = 0;
            int misses = 0;
            int nonMeleeResists = 0;
            int nonMeleeReflects = 0;
            double totalSwings = 0;
            double totalMeleeSwings = 0;
            double totalNonMeleeSwings = 0;
            double totalMeleeAvoids = 0;
            double totalNonMeleeAvoids = 0;

            ArrayList<Attack> attacks = c.getAttacks();
//            ArrayList<Attack> outgoingAttacks = new ArrayList<Attack>();
            ArrayList<Attack> incomingAttacks = new ArrayList<Attack>();
            ArrayList types = new ArrayList();

            for (Attack attack : attacks) {
                switch (attack.getAttackDirectionIntRelativeToCombatant(c)) {
//                    case Attack.ATTACK_TYPE_OUTGOING:
//                        outgoingAttacks.add(attack);
//                        break;
                    case Attack.ATTACK_TYPE_INCOMING:
                        incomingAttacks.add(attack);
                        break;
                    default:
                        break;
                }
            }

            for (Attack attack : incomingAttacks) {
                totalSwings++;
                if (attack.isMelee()) {
                    totalMeleeSwings++;
                } else if (attack.isNonMelee()) {
                    totalNonMeleeSwings++;
                }
                if (attack.isAvoided()) {
                    if (attack.isMelee()) {
                        totalMeleeAvoids++;
                    } else if (attack.isNonMelee()) {
                        totalNonMeleeAvoids++;
                    }
                    totalAvoids++;
                    if (attack.getReasonAvoided() != Attack.AVOID_TYPE_NO_DAMAGE) {
                        switch (attack.getReasonAvoided()) {
                            case Attack.AVOID_TYPE_COUNTER:
                                counters++;
                                break;
                            case Attack.AVOID_TYPE_BLOCK:
                                if (attack.getAttackClassInt() == Attack.ATTACK_TYPE_MELEE) {
                                    meleeBlocks++;
                                } else if (attack.getAttackClassInt() == Attack.ATTACK_TYPE_NON_MELEE) {
                                    nonMeleeBlocks++;
                                }
                                break;
                            case Attack.AVOID_TYPE_MELEE_DEFLECT:
                                deflects++;
                                break;
                            case Attack.AVOID_TYPE_MELEE_DODGE:
                                dodges++;
                                break;
                            case Attack.AVOID_TYPE_MELEE_MISS:
                                misses++;
                                break;
                            case Attack.AVOID_TYPE_MELEE_PARRY:
                                parries++;
                                break;
                            case Attack.AVOID_TYPE_MELEE_REFLECT:
                                meleeReflects++;
                                break;
                            case Attack.AVOID_TYPE_MELEE_RIPOSTE:
                                ripostes++;
                                break;
                            case Attack.AVOID_TYPE_NON_MELEE_REFLECT:
                                nonMeleeReflects++;
                                break;
                            case Attack.AVOID_TYPE_NON_MELEE_RESIST:
                                nonMeleeResists++;
                                break;
                            default:
                                break;
                        }
                    }
                }
            }

            ArrayList rows = new ArrayList();
            DecimalFormat df = new DecimalFormat("#,###,###.##");
//            "Avoid Type", "Number Avoided", "% Avoided"
            if (meleeBlocks > 0) {
                double blockPercent = meleeBlocks / totalMeleeSwings;
                String[] data = new String[3];
                data[0] = "Melee Block:";
                data[1] = meleeBlocks + "";
                data[2] = blockPercent * 100 + "";
                rows.add(data);

                String[] str = new String[2];
                str[0] = "Block";
                str[1] = blockPercent * 100 + "";
                types.add(str);
            }

            if (nonMeleeBlocks > 0) {
                double blockPercent = nonMeleeBlocks / totalNonMeleeSwings;
                String[] data = new String[3];
                data[0] = "Non-Melee Block:";
                data[1] = nonMeleeBlocks + "";
                data[2] = blockPercent * 100 + "";
                rows.add(data);

                String[] str = new String[2];
                str[0] = "Block";
                str[1] = blockPercent * 100 + "";
                types.add(str);
            }

            if (parries > 0) {
                double parryPercent = parries / totalMeleeSwings;
                String[] data = new String[3];
                data[0] = "Parry:";
                data[1] = parries + "";
                data[2] = parryPercent * 100 + "";
                rows.add(data);

                String[] str = new String[2];
                str[0] = "Parry";
                str[1] = parryPercent * 100 + "";
                types.add(str);
            }
            if (dodges > 0) {
                double dodgePercent = dodges / totalMeleeSwings;
                String[] data = new String[3];
                data[0] = "Dodge:";
                data[1] = dodges + "";
                data[2] = dodgePercent * 100 + "";
                rows.add(data);

                String[] str = new String[2];
                str[0] = "Dodge";
                str[1] = dodgePercent * 100 + "";
                types.add(str);
            }
            if (misses > 0) {
                double missPercent = misses / totalMeleeSwings;
                String[] data = new String[3];
                data[0] = "Miss:";
                data[1] = misses + "";
                data[2] = missPercent * 100 + "";
                rows.add(data);

                String[] str = new String[2];
                str[0] = "Miss";
                str[1] = missPercent * 100 + "";
                types.add(str);
            }
            if (ripostes > 0) {
                double ripostePercent = ripostes / totalMeleeSwings;
                String[] data = new String[3];
                data[0] = "Riposte:";
                data[1] = ripostes + "";
                data[2] = ripostePercent * 100 + "";
                rows.add(data);

                String[] str = new String[2];
                str[0] = "Riposte";
                str[1] = ripostePercent * 100 + "";
                types.add(str);
            }
            if (deflects > 0) {
                double deflectPercent = deflects / totalMeleeSwings;
                String[] data = new String[3];
                data[0] = "Deflect:";
                data[1] = deflects + "";
                data[2] = deflectPercent * 100 + "";
                rows.add(data);

                String[] str = new String[2];
                str[0] = "Deflect";
                str[1] = deflectPercent * 100 + "";
                types.add(str);
            }
            if (counters > 0) {
                double counterPercent = counters / totalMeleeSwings;
                String[] data = new String[3];
                data[0] = "Counter:";
                data[1] = counters + "";
                data[2] = counterPercent * 100 + "";
                rows.add(data);

                String[] str = new String[2];
                str[0] = "Counter";
                str[1] = counterPercent * 100 + "";
                types.add(str);
            }
            if (meleeReflects > 0) {
                double meleeReflectPercent = meleeReflects / totalMeleeSwings;
                String[] data = new String[3];
                data[0] = "Melee Reflect: ";
                data[1] = meleeReflects + "";
                data[2] = meleeReflectPercent * 100 + "";
                rows.add(data);

                String[] str = new String[2];
                str[0] = "Reflect (Melee)";
                str[1] = meleeReflectPercent * 100 + "";
                types.add(str);
            }
            if (nonMeleeResists > 0) {
                double nonMeeleResistPercent = nonMeleeResists / totalNonMeleeSwings;
                String[] data = new String[3];
                data[0] = "Resist:";
                data[1] = nonMeleeResists + "";
                data[2] = nonMeeleResistPercent * 100 + "";
                rows.add(data);

                String[] str = new String[2];
                str[0] = "Spell Resist";
                str[1] = nonMeeleResistPercent * 100 + "";
                types.add(str);
            }
            if (nonMeleeReflects > 0) {
                double nonMeleeReflectPercent = nonMeleeReflects / totalNonMeleeSwings;
                String[] data = new String[3];
                data[0] = "Spell Reflect:";
                data[1] = nonMeleeReflects + "";
                data[2] = nonMeleeReflectPercent * 100 + "";
                rows.add(data);

                String[] str = new String[2];
                str[0] = "Reflect (Spell)";
                str[1] = nonMeleeReflectPercent * 100 + "";
                types.add(str);
            }

            if (totalAvoids > 0) {
                double totalAvoidPercent = totalAvoids / totalSwings;
                String[] data = new String[3];
                data[0] = "Total Attacks Avoided";
                data[1] = totalAvoids + "";
                data[2] = totalAvoidPercent * 100 + "";
                rows.add(data);
            }

            for (int x = 0; x < rows.size(); x++) {
                String[] tmp = (String[]) rows.get(x);
                if (tmp[0].contains("Reflect")) {
                    lblSpellReflect.setText(tmp[0] + " " + tmp[1] + " (" + df.format(Double.parseDouble(tmp[2])) + "%)");
                } else if (tmp[0].equalsIgnoreCase("Resist:")) {
                    lblResist.setText(tmp[0] + " " + tmp[1] + " (" + df.format(Double.parseDouble(tmp[2])) + "%)");
                } else if (tmp[0].equalsIgnoreCase("Melee Reflect:")) {
                    lblMeleeReflect.setText(tmp[0] + " Melee " + tmp[1] + " (" + df.format(Double.parseDouble(tmp[2])) + "%)");
                } else if (tmp[0].equalsIgnoreCase("Counter:")) {
                    lblCounter.setText(tmp[0] + " " + tmp[1] + " (" + df.format(Double.parseDouble(tmp[2])) + "%)");
                } else if (tmp[0].equalsIgnoreCase("Deflect:")) {
                    lblDeflect.setText(tmp[0] + " " + tmp[1] + " (" + df.format(Double.parseDouble(tmp[2])) + "%)");
                } else if (tmp[0].equalsIgnoreCase("Riposte:")) {
                    lblRiposte.setText(tmp[0] + " " + tmp[1] + " (" + df.format(Double.parseDouble(tmp[2])) + "%)");
                } else if (tmp[0].equalsIgnoreCase("Miss:")) {
                    lblMiss.setText(tmp[0] + " " + tmp[1] + " (" + df.format(Double.parseDouble(tmp[2])) + "%)");
                } else if (tmp[0].equalsIgnoreCase("Dodge:")) {
                    lblDodge.setText(tmp[0] + " " + tmp[1] + " (" + df.format(Double.parseDouble(tmp[2])) + "%)");
                } else if (tmp[0].equalsIgnoreCase("Parry:")) {
                    lblParry.setText(tmp[0] + " " + tmp[1] + " (" + df.format(Double.parseDouble(tmp[2])) + "%)");
                } else if (tmp[0].equalsIgnoreCase("Melee Block:")) {
                    lblMeleeBlock.setText(tmp[0] + " " + tmp[1] + " (" + df.format(Double.parseDouble(tmp[2])) + "%)");
                } else if (tmp[0].equalsIgnoreCase("Non-Melee Block:")) {
                    lblNonMeleeBlock.setText(tmp[0] + " " + tmp[1] + " (" + df.format(Double.parseDouble(tmp[2])) + "%)");
                }
            }

            DecimalFormat df2 = new DecimalFormat("###,###,###");
            if (totalMeleeAvoids > 0) {
                lblMeleeTotal.setText("Total: " + df2.format(totalMeleeAvoids) + " (" + df.format(((double) (totalMeleeAvoids / totalMeleeSwings)) * 100) + "%)");
            }

            if (totalNonMeleeAvoids > 0) {
                lblNonMeleeTotal.setText("Total: " + df2.format(totalNonMeleeAvoids) + " (" + df.format(((double) (totalNonMeleeAvoids / totalNonMeleeSwings)) * 100) + "%)");
            }

            DefaultPieDataset dataset = new DefaultPieDataset();

            df = new DecimalFormat("###.##");
            Collections.sort(types, new LegendCompare());

            for (int x = 0; x < types.size(); x++) {
                String[] tmp = (String[]) types.get(x);
                dataset.setValue(df.format(Double.parseDouble(tmp[1])) + "% - " + tmp[0], Double.parseDouble(tmp[1]));
            }

            chart = ChartFactory.createPieChart(
                    "Avoid Types", // chart title
                    dataset, // chart data
                    true,
                    true,
                    false);
            PiePlot plot = (PiePlot) chart.getPlot();
            plot.setDirection(Rotation.ANTICLOCKWISE);

            // Specify the colors here
            Color[] colors = {Color.blue, Color.yellow, Color.green, Color.orange, Color.red, Color.black, Color.pink, Color.gray, Color.magenta, Color.cyan};
            PieRenderer renderer = new PieRenderer(colors, false);
            renderer.setColor(plot, dataset);

            BufferedImage image = chart.createBufferedImage(jLabel1.getSize().width, jLabel1.getSize().height);
            jLabel1.setIcon(new ImageIcon(image));
            rval = (int) totalAvoids;
        }
        return rval;
    }

    private static class LegendCompare implements Comparator {

        public LegendCompare() {
        }

        public int compare(Object o1, Object o2) {
            String[] s1 = (String[]) o1;
            String[] s2 = (String[]) o2;
            int rval = 0;

            double percent1 = Double.parseDouble(s1[1]);
            double percent2 = Double.parseDouble(s2[1]);

            if (percent1 > percent2) {
                rval = -1;
            } else if (percent1 < percent2) {
                rval = 1;
            } else {
                rval = -1;
            }

            return rval;
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLayeredPane1 = new javax.swing.JLayeredPane();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jList1 = new JList(new DefaultListModel());
        jCheckBox1 = new javax.swing.JCheckBox();
        jCheckBox2 = new javax.swing.JCheckBox();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        lblDodge = new javax.swing.JLabel();
        lblMeleeBlock = new javax.swing.JLabel();
        lblParry = new javax.swing.JLabel();
        lblRiposte = new javax.swing.JLabel();
        lblCounter = new javax.swing.JLabel();
        lblDeflect = new javax.swing.JLabel();
        lblMeleeReflect = new javax.swing.JLabel();
        lblResist = new javax.swing.JLabel();
        lblSpellReflect = new javax.swing.JLabel();
        lblNonMeleeTotal = new javax.swing.JLabel();
        lblMiss = new javax.swing.JLabel();
        lblMeleeTotal = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        lblTotalMelee = new javax.swing.JLabel();
        lblTotalNonMelee = new javax.swing.JLabel();
        lblTotalTotal = new javax.swing.JLabel();
        lblNonMeleeBlock = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Avoidance Report");
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                formComponentResized(evt);
            }
        });

        jLayeredPane1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setText("jLabel1");
        jLabel1.setBounds(4, 4, 240, 170);
        jLayeredPane1.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jList1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jList1MouseClicked(evt);
            }
        });
        jList1.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                jList1ValueChanged(evt);
            }
        });
        jScrollPane2.setViewportView(jList1);

        jCheckBox1.setSelected(true);
        jCheckBox1.setText("Display Allies");
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });

        jCheckBox2.setSelected(true);
        jCheckBox2.setText("Display Enemies");
        jCheckBox2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox2ActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel2.setText("Melee Avoidance");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel3.setText("Non-Melee Avoidance");

        lblDodge.setText("Dodge:");

        lblMeleeBlock.setText("Block:");

        lblParry.setText("Parry:");

        lblRiposte.setText("Riposte:");

        lblCounter.setText("Counter:");

        lblDeflect.setText("Deflect:");

        lblMeleeReflect.setText("Reflect:");

        lblResist.setText("Resist:");

        lblSpellReflect.setText("Reflect:");

        lblNonMeleeTotal.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblNonMeleeTotal.setText("Total:");

        lblMiss.setText("Miss:");

        lblMeleeTotal.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblMeleeTotal.setText("Total:");

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel4.setText("Total Avoidance");

        lblTotalMelee.setText("Melee:");

        lblTotalNonMelee.setText("Non-Melee:");

        lblTotalTotal.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblTotalTotal.setText("Total:");

        lblNonMeleeBlock.setText("Block:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jCheckBox2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jCheckBox1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(lblParry, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(lblMeleeBlock, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(lblRiposte, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addComponent(lblDodge, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
                            .addComponent(lblDeflect, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
                            .addComponent(lblCounter, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
                            .addComponent(lblMeleeReflect, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
                            .addComponent(lblMiss, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
                            .addComponent(lblMeleeTotal, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lblTotalMelee, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
                            .addComponent(lblTotalNonMelee, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
                            .addComponent(lblTotalTotal, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(lblNonMeleeTotal, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(lblNonMeleeBlock, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(lblResist, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(lblSpellReflect, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                    .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 394, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jCheckBox1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCheckBox2)
                        .addGap(6, 6, 6)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 504, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel4)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(lblTotalMelee, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(lblTotalNonMelee, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(18, 18, 18)
                                        .addComponent(lblMeleeReflect, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(lblMiss, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(8, 8, 8)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(lblTotalTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(lblMeleeTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 334, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblMeleeBlock, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblParry, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(6, 6, 6)
                                .addComponent(lblRiposte, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblResist, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblSpellReflect, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblNonMeleeBlock, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(lblDodge, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblDeflect)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblCounter, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(lblNonMeleeTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)))))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
        DefaultListModel model = (DefaultListModel) this.jList1.getModel();
        //allies
        if (this.jCheckBox1.isSelected() && !this.jCheckBox2.isSelected()) {
            this.populateList(enc, true, false);
        } else if (!this.jCheckBox1.isSelected() && this.jCheckBox2.isSelected()) {
            this.populateList(enc, false, true);
        } else if (this.jCheckBox1.isSelected() && this.jCheckBox2.isSelected()) {
            this.populateList(enc, true, true);
        } else if (!this.jCheckBox1.isSelected() && !this.jCheckBox2.isSelected()) {
            model.clear();
        }
}//GEN-LAST:event_jCheckBox1ActionPerformed

    private void jCheckBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox2ActionPerformed
        DefaultListModel model = (DefaultListModel) this.jList1.getModel();
        //enemies
        if (this.jCheckBox1.isSelected() && !this.jCheckBox2.isSelected()) {
            this.populateList(enc, true, false);
        } else if (!this.jCheckBox1.isSelected() && this.jCheckBox2.isSelected()) {
            this.populateList(enc, false, true);
        } else if (this.jCheckBox1.isSelected() && this.jCheckBox2.isSelected()) {
            this.populateList(enc, true, true);
        } else if (!this.jCheckBox1.isSelected() && !this.jCheckBox2.isSelected()) {
            model.clear();
        }
    }//GEN-LAST:event_jCheckBox2ActionPerformed

    private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jList1ValueChanged
    }//GEN-LAST:event_jList1ValueChanged

    private void jList1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jList1MouseClicked
        DefaultListModel model = (DefaultListModel) this.jList1.getModel();
        try {
            if (this.jList1.getSelectedIndex() >= 0) {
//                System.out.println();
                int totalAvoids = this.generateAvoidanceReport((Combatant) model.get(this.jList1.getSelectedIndex()));
                if (totalAvoids == 0) {
                    model.remove(this.jList1.getSelectedIndex());
                }
            }
        } catch (NullPointerException ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_jList1MouseClicked

    private void formComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentResized
        jLabel1.setSize(this.jLayeredPane1.getWidth(), this.jLayeredPane1.getHeight());
        if (this.chart != null) {
            BufferedImage image = chart.createBufferedImage(jLabel1.getSize().width, jLabel1.getSize().height);
            jLabel1.setIcon(new ImageIcon(image));
        }
    }//GEN-LAST:event_formComponentResized
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JCheckBox jCheckBox2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JList jList1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lblCounter;
    private javax.swing.JLabel lblDeflect;
    private javax.swing.JLabel lblDodge;
    private javax.swing.JLabel lblMeleeBlock;
    private javax.swing.JLabel lblMeleeReflect;
    private javax.swing.JLabel lblMeleeTotal;
    private javax.swing.JLabel lblMiss;
    private javax.swing.JLabel lblNonMeleeBlock;
    private javax.swing.JLabel lblNonMeleeTotal;
    private javax.swing.JLabel lblParry;
    private javax.swing.JLabel lblResist;
    private javax.swing.JLabel lblRiposte;
    private javax.swing.JLabel lblSpellReflect;
    private javax.swing.JLabel lblTotalMelee;
    private javax.swing.JLabel lblTotalNonMelee;
    private javax.swing.JLabel lblTotalTotal;
    // End of variables declaration//GEN-END:variables
}
